# It is recommended to test the script on a local machine for its purpose and effects. # ManageEngine Desktop Central will not be responsible for any # damage/loss to the data/setup based on the behavior of the script. # Description - Script to Add User # Parameters - "" "" "" # Remarks - If group is not given, user will be added to the Admin group. # Configuration Type - COMPUTER #!/bin/bash if [ $# -gt '1' ]; then if id "$1"; then echo "user already exist" exit 1 else echo "User does not already exist - So proceeding user creation" if [ -z "$3" ]; then group="admin" else group=$3 fi username=$1 password=$2 MAXID=$(dscl . -list /Users UniqueID | awk '{print $2}' | sort -ug | tail -1) USERID=$((MAXID+1)) sudo dscl . -create /Users/"$username" sudo dscl . -create /Users/"$username" UserShell /bin/bash sudo dscl . -create /Users/"$username" RealName "$username" sudo dscl . -create /Users/"$username" UniqueID "$USERID" sudo dscl . -create /Users/"$username" PrimaryGroupID 20 sudo dscl . -create /Users/"$username" NFSHomeDirectory /Users/$username sudo dscl . -passwd /Users/"$username" "$password" sudo dseditgroup -o edit -a "$username" -t user "$group" sudo createhomedir -c 2>&1 | grep -v "shell-init" fi else echo "Invalid Arguments - Please refer description of Script" exit 1 fi